﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Net.Sockets;
using System.IO;

namespace MapReduce.Comm.IO
{
    public interface IOStream
    {
        //String GetAddress();
        //ushort GetPort();
        ulong Read(byte[] b);
        void Write(byte[] pData);
        void Close();
    }

    public class SocketIOStream : IOStream
    {
        private Socket mSocket;

        public SocketIOStream(Socket pSocket )
        {
            mSocket = pSocket;
        }
        public ulong Read(byte[] pData)
        {
            return (ulong)mSocket.Receive(pData);
        }
        public void Write(byte[] pData)
        {
            mSocket.Send(pData);
        }
        public void Close()
        {
            mSocket.Close();
        }
    }//SocketIOStream


    public class StreamIOStream : IOStream
    {
        Stream mStream;

        public StreamIOStream(Stream pStream)
        {
            mStream = pStream;

        }

        public ulong Read(byte[] pData)
        {
            return (ulong)mStream.Read(pData, 0, pData.Length);
        }
        public void Write(byte[] pData)
        {
            mStream.Write(pData, 0, pData.Length);
        }

        public void Close()
        {
            mStream.Close();
        }
    }//StreamIOStream
}
